package oop;

import static com.google.common.collect.Lists.newArrayList;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

class Pair<T> {
    private final T a;
    private final T b;

    Pair(final T a, final T b) {
        this.a = a;
        this.b = b;
    }

    public T getA() {
        return a;
    }

    public T getB() {
        return b;
    }
    static  class  PairIterator<T> implements Iterator<Pair<T>>{

        private Iterator<T> iter;
        private T curItem;

        public PairIterator(final List<T> list) {
            this.iter = list.iterator();
            this.curItem = iter.hasNext()?iter.next():null;
        }

        @Override
        public boolean hasNext() {
            if(curItem==null || !iter.hasNext()) return false;
            return true;
        }

        @Override
        public Pair<T> next() {
            return new Pair<T>(curItem,curItem=iter.next());
        }

    }
    
    static public <T> Iterable<Pair<T>> toPairIterable(final List<T> list){
        return new Iterable<Pair<T>>() {
            @Override
            public Iterator<Pair<T>> iterator() {
                return new PairIterator<T>(list);

        };
    };
    }
}


public class Yanghui {
    public static List<Integer> nextLine(final List<Integer> curLine) {
        List<Integer> result = new ArrayList<Integer>();

        result.add(1);
        
        for (Pair<Integer> p : Pair.toPairIterable(curLine)) {
            result.add(p.getA() + p.getB());
        }
        result.add(1);
        return result;
    }

    public static void main(String[] args) {
        System.out.println(nextLine(newArrayList(1))); //[1,1]
        System.out.println(nextLine(newArrayList(1,1)));//[1,2,1]
        System.out.println(nextLine(newArrayList(1,2,1)));//[1,3,3,1]
    }
}